//
//  MTZMainViewController.swift
//  weibomtz
//
//  Created by 毛铁柱 on 16/10/14.
//  Copyright © 2016年 mtz. All rights reserved.
//

import UIKit

class MTZMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 将当前tabbarController的tabbar换成我们自己的tabbar
        let tabBar = MTZTabBar()
        tabBar.composeButtonClickClourse = {
        print("你妹的")
        
        }
        self.setValue(tabBar, forKeyPath: "tabBar")
        

        // Do any additional setup after loading the view.
        addChildViewControllers()
        // 统一设置tabbar的颜色
//        tabBar.tintColor = UIColor.orangeColor()
       
    }

    // 添加4个子控制器
    func addChildViewControllers() {
         addChildViewController(MTZHomeTableViewController(), title: "首页",imageNamed: "tabbar_home")
         addChildViewController(MTZMessageTableViewController(), title: "消息",imageNamed: "tabbar_message_center")
        addChildViewController(MTZDiscoverTableViewController(), title: "发现",imageNamed: "tabbar_discover")
         addChildViewController(MTZProfileTableViewController(), title: "我",imageNamed: "tabbar_profile")

//        addChildViewController(MTZHomeTableViewController(), title: "首页",imageNamed: "allproducts_selected")
//        addChildViewController(MTZMessageTableViewController(), title: "消息",imageNamed: "allproducts_selected")
//        addChildViewController(MTZDiscoverTableViewController(), title: "发现",imageNamed: "allproducts_selected")
//        addChildViewController(MTZProfileTableViewController(), title: "我",imageNamed: "allproducts_selected")
    
    
    }
    func addChildViewController(childController: UIViewController, title:String, imageNamed:String)
    {
        //设置标题
        childController.title = title
//        childController.navigationItem.title = title
//        childController.tabBarItem.title = title
        
        //设置图标
        childController.tabBarItem.image = UIImage(named: imageNamed)
        //让图标原样显示
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageNamed)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        //设置文字颜色
        let attributed = [NSForegroundColorAttributeName:UIColor.orangeColor()]
        childController.tabBarItem.setTitleTextAttributes(attributed, forState:UIControlState.Selected)
        
//        //设置文字字体
//        let fontAttr = [NSFontAttributeName:UIFont.systemFontOfSize(15)]
//        childController.tabBarItem.setTitleTextAttributes(fontAttr, forState: UIControlState.Normal)
//        // 调整图片位置
//        childController.tabBarItem.imageInsets = UIEdgeInsets(top: 5, left: 0, bottom: -5, right: 0)
        //添加子控制器
        addChildViewController(MTZNavigationController(rootViewController: childController))
        
    }
        
    
    

    }
